//package com.ge.modules.wx;
//
//import com.ge.modules.api.service.TbUserService;
//import com.ge.modules.api.service.TbTokenService;
//import com.ge.modules.entity.TbUser;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 授权后的回调请求处理
// * Created by wuye on 2018/3/5.
// */
//@RestController
//@RequestMapping("/oauth")
//public class OAuthController {
//
//    @Autowired
//    private TbUserService tbUserService;
//
//    @Autowired
//    private TbTokenService tbTokenService;
//
//
//    @GetMapping("/auth")
//    public ModelAndView doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        request.setCharacterEncoding("utf-8");
//        response.setCharacterEncoding("utf-8");
//
//        // 用户同意授权后，能获取到code
//        String code = request.getParameter("code");
//        String state = request.getParameter("state");
//        Map<String, Object> map = new HashMap<>();
//        // 用户同意授权
//        if (!"authdeny".equals(code)) {
//            // 获取网页授权access_token
//            WeixinOauth2Token weixinOauth2Token = AdvancedUtil.getOauth2AccessToken("wxde9b9b1d6c4cc2df", "0ea12b593a6e81c756afe3813675c1cb", code);
//            // 网页授权接口访问凭证
//            String accessToken = weixinOauth2Token.getAccessToken();
//            // 用户标识
//            String openId = weixinOauth2Token.getOpenId();
//            // 获取用户信息
//            SNSUserInfo snsUserInfo = AdvancedUtil.getSNSUserInfo(accessToken, openId);
//            TbUser tbUser = tbUserService.queryOpenId(snsUserInfo.getOpenId());
//            map = tbTokenService.createToken(tbUser.getUserId());
//            // 设置要传递的参数
//            request.setAttribute("snsUserInfo", snsUserInfo);
//            request.setAttribute("state", state);
//        }
//        // 跳转到index.jsp
////         request.getRequestDispatcher("www.guangtouboy.com").forward(request, response);
////        ModelAndView view = new ModelAndView("redirect:http://www.guangtouboy.com/#/Login?token=" + map.get("token").toString());
////        view.addObject("state",state);
////        return view;
//        return new ModelAndView("redirect:http://www.guangtouboy.com/#/Login?state="+state+"&token=" + map.get("token").toString());
//    }
//}
